<?php
class Promotion_project_model extends CI_Model
{
    private $table = 'promotion_project';
    
    /**
     * 专题推广
     * @param array $belong 专题所属 1：景区；2：酒店；3：线路；4：商品
     * @param array $version 1：PC版 2：手机版
     * @param number $limit
     */
    public function findByPromotion($belong, $version=1, $limit=100)
    {
        $this->db->where_in('belong', $belong);
        $this->db->where('version', $version);
        $this->db->order_by('sort', 'ASC');
        $this->db->limit($limit);
        return $this->db->get($this->table);
    }
    
    public function total($getData=array())
    {
        if (!empty($getData['version'])) {
            $this->db->where_in('version', $getData['version']);
        } else {
            $this->db->where_in('version', array(1,2));
        }
        if (!empty($getData['belong'])) {
            $this->db->where_in('belong', $getData['belong']);
        } else {
            $this->db->where_in('belong', array(1,2,3,4));
        }
        
        if (!empty($getData['name'])) {
            $this->db->like('name', $getData['name']);
        }
        return $this->db->count_all_results($this->table);
    }
    
    /**
     * 专题推广
     * @param array $belong 专题所属 1：景区；2：酒店；3：线路；4：商品
     * @param array $version 1：PC版 2：手机版
     * @param number $limit
     */
    public function page_list($pernum, $start, $getData=array())
    {
        if (!empty($getData['version'])) {
            $this->db->where_in('version', $getData['version']);
        } else {
            $this->db->where_in('version', array(1,2));
        }
        if (!empty($getData['belong'])) {
            $this->db->where_in('belong', $getData['belong']);
        } else {
            $this->db->where_in('belong', array(1,2,3,4));
        }
        
        if (!empty($getData['name'])) {
            $this->db->like('name', $getData['name']);
        }
        $this->db->order_by('sort', 'DESC');
        $this->db->limit($pernum, $start);
        return $this->db->get($this->table);
    }
    
    public function addToPraise($id)
    {
        $this->db->set('praise', 'praise+1', false);
        $this->db->where('id', $id);
        return $this->db->update($this->table);
    }
}